/*Que : 6
 *  Write a program to implement time server using socket.
 * 
 * This is server.
 */

import java.net.*;
import java.io.*;
import java.util.*;
import sun.util.BuddhistCalendar;

/**
 *
 * @author root
 */
public class P6_server {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(888);
        System.out.println("Time server created at port no. 888");
        Socket s = ss.accept();
        PrintStream ps = new PrintStream(s.getOutputStream());
        Calendar calendar = new GregorianCalendar();
        String am_pm;
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        if (calendar.get(Calendar.AM_PM) == 0) {
            am_pm = "AM";
        } else {
            am_pm = "PM";
        }

        ps.print(hour+" : "); ps.flush();
        ps.print(minute+" : ");ps.flush();
        ps.print(second+" : ");ps.flush();
        ps.print("  "+am_pm);ps.flush();


        /*while (true) {
        String str, str1;
        while ((str = br.readLine()) != null) {
        System.out.println(str);
        ps.println(str);
        }*/
        ps.close();
        ss.close();
        s.close();
        System.exit(0);
    }
}